var lmask : int = 8189;

var mainCamera : Camera;

class CatViewInfo
{
	var sightLength : float=10;
	var headRadius : float=1;
	var sightAngle : float=90;

	public var viewCenter : Vector3;
	public var viewLimitPoint : Vector3[];
}

private var gui : GameHUD;
var viewInfo : CatViewInfo;

function Start()
{
	gui = mainCamera.gameObject.GetComponent("GameHUD");

	gui.setCatInfo(viewInfo);
}

function Update () 
{
	viewInfo.viewCenter = transform.position;
	var cdir : float = -transform.eulerAngles.y * Mathf.Deg2Rad;
	var ad = viewInfo.sightAngle * Mathf.Deg2Rad/2;
	var s = cdir-ad;
	var e = cdir+ad;
	var c : float = viewInfo.viewLimitPoint.length-1.0;
	for (var i : int; i < viewInfo.viewLimitPoint.length; i++)
	{
		var hit : RaycastHit;
		var dir : float = (i*e + (-i+c)*s)/c;
		var vdir : Vector3 = Vector3(Mathf.Cos(dir),0, Mathf.Sin(dir));
		if (Physics.Raycast(viewInfo.viewCenter+vdir*viewInfo.headRadius, vdir, hit, viewInfo.sightLength-viewInfo.headRadius, lmask))
			vdir = hit.point;
		else
			vdir = vdir*viewInfo.sightLength + viewInfo.viewCenter;
		viewInfo.viewLimitPoint[i] = vdir;
		Debug.DrawLine(viewInfo.viewCenter, vdir);
	}
}